import React , { useEffect,useContext } from 'react';


import { withRouter,NavLink} from 'react-router-dom';
import {observer,MobXProviderContext} from 'mobx-react';

// hook中使用mobx
/**
https://mobx-react.js.org/recipes-migration
https://www.jianshu.com/p/55ba6d415bb1

1、调用方式
export default withRouter(observer(View));
2、获取
import {observer,MobXProviderContext} from 'mobx-react';
3、自定义一个hook
function useStores() {
  return React.useContext(MobXProviderContext)
}
4、直接获取
const {obs} = useStores()
5、原方式不变

6、inject
function useStores(name) {
  return React.useContext(MobXProviderContext)[name]
}
*/
function useStores(name) {
    return React.useContext(MobXProviderContext)[name]
}

const View = (props)=>{
    const {objCfg,updateNameStr,num} = useStores('obs')
    const {tradeCfg} = useStores('first')
    const doAction = (e)=>{
        updateNameStr(num,'ssss')
    }
    useEffect(()=>{

    })
    return(
        <div className="m">
        <p>创建store/obs.js文件</p>
        <p>直接接受：{objCfg.name}</p>
        <p>直接接受：{tradeCfg.sadf}</p>
        <p>接受描述：{objCfg.des}</p>
        <p>接受描述：<input type="button" onClick={(e)=>doAction(e)} value="点击改变"/></p>
        </div>
    )
}
// export default View;
export default withRouter(observer(View));
